
var user_map =null;
var time_count=0;
exports.init=function(arg){
    user_map = new Map();
    time_count=arg;
    setInterval(this.remove_userMap,1000*1);
};

exports.add_userMap=function(account,key,ackey,info){
    if(this.is_userMap_exist(key)){
        user_map.delete(key);
    }else{
        user_map.forEach(function (item, key, mapObj) {
            if(item.account==account){
                user_map.delete(key);
            }
        });
    }
    var t=new Date().getTime();
    user_map.set(key,{account:account,ackey:ackey,info:info,time:t});
};

exports.remove_userMap=function(){
    var t=new Date().getTime();
    user_map.forEach(function (item, key, mapObj) {
        if(t-new Date(item.time).getTime()>=time_count){
            console.log('remove >>>>>>> key--'+key+"    "+(t-new Date(item.time).getTime()));
            console.log(item);
            user_map.delete(key);
        }
    });
};

exports.get_user=function(key){
    if(this.is_userMap_exist(key)){
        return user_map.get(key);
    }
    return null;
};

exports.is_userMap_exist=function(key){
    if(user_map.has(key)){
        return true;
    }
    return false;
};

exports.is_key_exist=function(key){
    if(this.is_userMap_exist(key)){
        var t=new Date().getTime();
        var item = user_map.get(key);
        if(t-new Date(item.time).getTime()>=time_count){
            user_map.delete(key);
            return false;
        }else{
            return true;
        }
    }else{
        return false;
    }
};

exports.return_size=function(){
    return user_map.size;
};